<?php
namespace Common\Model;
use Think\Model;

/**
 * Class PumpGateModel
 * @package Common\Model
 * 泵站闸门
 */
class PumpGateModel extends BaseModel{
    public $pix = "";
    public $fieldsStr = '*';
    public $orderStr = 'ps_id desc,scrmach_id desc,gate_name asc';

    public function field_array(){
        /**
         * type:
         * 0，不显示字段
         * 1，文本框
         * 2，下拉框
         * 3，数值查询，带条件
         * 4，日期查询，带条件
         */
        $array = array(
            'base' => array(
                'text' => '基本信息',
                'children'=>array(
                    array('field'=>'ps_id','text' => '','type'=>0),
                    array('field'=>'scrmach_id','text' => '','type'=>0),
                    array('field'=>'gate_id','text' => '闸门编码','type'=>1),
                    array('field'=>'gate_name','text' => '闸门名称','type'=>1),
                    array('field'=>'gate_typ','text' => '闸门类型','type'=>2,'option_text'=>gate_typ()),
                    array('field'=>'gate_mfr','text' => '生产厂家','type'=>1),
                    array('field'=>'gate_model','text' => '型号','type'=>1),
                    array('field'=>'gate_motor_power','text' => '电机功率(千瓦)','type'=>3,'condition'=>get_condition_array()),
                    array('field'=>'gata_elev','text' => '闸门高程(米)','type'=>3,'condition'=>get_condition_array()),
                    array('field'=>'gate_h','text' => '闸门净高(米)','type'=>3,'condition'=>get_condition_array()),
                    array('field'=>'gate_wid','text' => '闸门净宽(米)','type'=>3,'condition'=>get_condition_array()),
                    array('field'=>'gate_typ','text' => '闸门控制类型','type'=>2,'option_text'=>gate_cont_type_option()),
                    array('field'=>'gate_typ','text' => '闸门启闭型式','type'=>2,'option_text'=>gate_swit_sty_option()),
                    array('field'=>'gate_row_num','text' => '闸门排数','type'=>3,'condition'=>get_condition_array()),
                    array('field'=>'gate_hole_num','text' => '闸门孔数','type'=>3,'condition'=>get_condition_array()),
                    array('field'=>'gate_svc_dt','text' => '投运日期','type'=>4,'condition'=>get_condition_array()),
                ),
            ),
        );
        return $array;
    }

    public function get_list_use_page($map=array(), $cur_page, $rows_num){
        $map_filter = filter_query_map_get_order_str($map, $this->orderStr);
        $map = $map_filter['map'];
        $order_str = $map_filter['order_str'];
        $map = filter_field_array($this->field_array(), $map);
        $count = $this->where($map)->count();
        $list = $this->where($map)->order($order_str)->page($cur_page.",$rows_num")->select();
        $station_model = D('PumpingStation');
        $mac_model = D('PumpGate');
        foreach($list as $k => $v){
            $sta_temp = $station_model->queryObj($v['ps_id'], 'id');
            $list[$k]['sta_name'] = $sta_temp['ps_name'];
            $mac_temp = $mac_model->queryObj($v['scrmach_id'], 'id');
            $list[$k]['scrmach_id'] = $mac_temp['scrmach_name'];
            $list[$k]['gate_typ'] = gate_typ($list[$k]['gate_typ'], false);
            $list[$k]['gate_cntl_typ'] = gate_cont_type_option($list[$k]['gate_cntl_typ'], false);
            $list[$k]['gate_swit_sty'] = gate_swit_sty_option($list[$k]['gate_swit_sty'], false);
        }
        return array('total'=>$count, 'list'=>$list);
    }

    public function filter_all(){
        $station_model = D('PumpingStation');
        $list = $this->getAll();
        foreach($list as $k => $v){
            $fa = $station_model->queryObj($list[$k]['ps_id'], 'id');
            $list[$k]['ps_id'] = $fa['ps_name'];
        }
        return $list;
    }
}